package io.github.sruby.hadoop.mr;

import io.github.sruby.hadoop.PartitionerApp;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * mr wordcount
 *
 * @author sruby on
 */
public class MyWC {
    public static void main(String[] args) throws IOException {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);
        job.setJarByClass(MyWC.class);

        job.setJobName("myjob");

        Path inpath = new Path("/mytemp/haha2.txt");
        FileInputFormat.addInputPath(job,inpath);
        Path outPath = new Path("/mp-output/mywc");

        if (outPath.getFileSystem(conf).exists(outPath)){
            outPath.getFileSystem(conf).delete(outPath,true);
        }
        FileOutputFormat.setOutputPath(job,outPath);

        job.setMapperClass(MyMapper.class);
        job.setReducerClass(MyReducer.class);
    }
}
